/*
 * Classic.js
 * Classic
 * Copyright (C) Jorge H. C. Lucema.
 */

/*global BigInteger */

var Classic = (function () {

//    "use strict";
    /**
     * 
     * @param {type} m
     * @returns {Classic_L9.Classic}
     */
    var Classic = function (m) {
        this.m = m;
    };

    Classic.cConvert = function (x) {
        if (x.s < 0 || x.compareTo(this.m) >= 0) {
            return x.mod(this.m);
        }
        return x;
    };

    Classic.cSqrTo = function (x, r) {
        x.squareTo(r);
        this.reduce(r);
    };

    Classic.cReduce = function (x) {
        x.divRemTo(this.m, null, x);
    };

    Classic.cMulTo = function (x, y, r) {
        x.multiplyTo(y, r);
        this.reduce(r);
    };

    Classic.cRevert = function (x) {
        return x;
    };

    Classic.prototype.convert = Classic.cConvert;
    Classic.prototype.sqrTo = Classic.cSqrTo;
    Classic.prototype.reduce = Classic.cReduce;
    Classic.prototype.mulTo = Classic.cMulTo;
    Classic.prototype.revert = Classic.cRevert;

    return Classic;
}());